package com.easygem.business.service.imp;

import com.easygem.business.mapper.BgClientMapper;
import com.easygem.business.service.BgClientService;
import com.easygem.business.service.base.AbstractServiceImpl;
import com.easygem.common.model.business.BgClient;
import com.easygem.common.model.system.Employee;
import com.easygem.common.response.ActiveUser;
import com.easygem.common.vo.business.BgClientVO;
import com.easygem.common.vo.system.PageVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 肖智
 * @version 1.0
 * @Description TODO
 * @date 2025/1/14
 */
@Service
public class BgClientServiceImpl extends AbstractServiceImpl<BgClientMapper, BgClient, Integer> implements BgClientService {
    @Autowired
    private BgClientMapper bgClientMapper;

    /**
     * 查询客户
     *
     * @param bgClientVO
     * @return
     */
    @Override
    public PageVO<BgClient> selectBgClientList(Integer pageNum, Integer pageSize, BgClientVO bgClientVO) {
        PageHelper.startPage(pageNum, pageSize);
        ActiveUser activeUser = (ActiveUser) SecurityUtils.getSubject().getPrincipal();
        Employee employee = activeUser.getEmployee();
        if (employee.getType()!=0){
            bgClientVO.setEmployeeIdAftermarket(employee.getEmpId());
        }
        List<BgClient> bgClientList = bgClientMapper.selectBgClientList(bgClientVO);
        PageInfo<BgClient> info = new PageInfo<>(bgClientList);
        return new PageVO<>(info.getTotal(), bgClientList);
    }

    /**
     * 删除客户
     *
     * @param clientId
     * @return
     */
    @Override
    public Integer deleteBgClientByClientId(Long clientId) {
        return bgClientMapper.deleteBgClientByClientId(clientId);
    }

    /**
     * 添加客户
     *
     * @param map
     * @return
     */
    @Override
    public Integer addBgClient(Map<String, Object> map) {
        return bgClientMapper.addBgClient(map);
    }

    /**
     * 修改客户
     *
     * @param map
     * @return
     */
    @Override
    public Integer editBgClient(Map<String, Object> map) {
        return bgClientMapper.editBgClient(map);
    }

    /**
     * 加关注
     *
     * @param clientId
     * @return
     */
    @Override
    public Integer addAttention(Long clientId) {
        return bgClientMapper.addAttention(clientId);
    }

    /**
     * 取关
     *
     * @param clientId
     * @return
     */
    @Override
    public Integer cancelAttention(Long clientId) {
        return bgClientMapper.cancelAttention(clientId);
    }
}
